package com.py.androidUtils.UI;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.py.androidUtils.UI.adapter.ArticleDetailsAdapter;
import com.py.androidUtils.UI.adapter.ArticleDetailsAdapter.ArticleDetailsClik;
import com.py.androidUtils.UI.view.MyWebView;
import com.py.androidUtils.UI.view.ShowShareView;
import com.py.androidUtils.UI.view.emoji.FaceConversionUtil;
import com.py.androidUtils.UI.view.emoji.FaceRelativeLayout;
import com.py.androidUtils.base.BaseListActivity;
import com.py.androidUtils.pulltorefrsh.PullToRefreshBase.Mode;
import com.py.androidUtils.utils.KeyBoardUtils;
import com.py.androidUtils.utils.LoadingImages;
import com.py.androidUtils.utils.TextDrawableUnits;
import com.py.androidUtils.utils.ToastUtil;
import com.readyidu.app.R;

public class ArticleDetailsActivity extends BaseListActivity<Object> {
	private int type = 1;
	private ImageView userImg;
	private TextView userName;
	private ImageView attention;
	private TextView title;
	private WebView webView;
	private TextView label;
	private TextView content;
	private LinearLayout linePraise;
	private ImageView ivPraise;
	private TextView tvPraise;
	private LinearLayout lineMessage;
	private TextView tvMessage;
	private LinearLayout lineCollection;
	private ImageView ivCollection;
	private LinearLayout lineShare;
	private LinearLayout lineReport;
	private LinearLayout line_bg;

	private RelativeLayout loadImage;
	private ImageView img;
	private TextView imgNumber;

	private MyWebView myWebView;

	private RelativeLayout facechoose;
	private FaceRelativeLayout layout;
	private EditText edMessage;
	private ImageView showEmojii;

	private ImageView btnSend;

	private boolean isAttention = true;

	private boolean isPraise = true;

	@Override
	public void onActivityCreatedCallBack() {
		getTitleActionBar().setTitleBar("详情");
		getTitleActionBar().setImgLeft(R.drawable.icon_back, new OnClickListener() {
			@Override
			public void onClick(View v) {
				finishactivity(ArticleDetailsActivity.this);
			}
		});
		commAdapter = new ArticleDetailsAdapter(ArticleDetailsActivity.this);
		img.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				ArrayList<String> list = new ArrayList<String>();
				list.add("http://pic1.nipic.com/2008-09-08/200898163242920_2.jpg");
				list.add("http://pic25.nipic.com/20121209/9252150_194258033000_2.jpg");
				list.add("http://pic1.nipic.com/2008-08-12/200881211331729_2.jpg");
				list.add("http://pic1.nipic.com/2008-09-08/200898163242920_2.jpg");
				list.add("http://ww1.sinaimg.cn/large/bca3622fjw1dzoqcklkcaj.jpg");
				list.add("http://img.ziling.com/month_1112/1112241817da91872ab68c40f9.jpg");
				list.add("http://ww1.sinaimg.cn/large/8110d223jw1dzm5czd9h6j.jpg");
				list.add("http://ww1.sinaimg.cn/large/bcc86cc5jw1dzb4o8im2gj.jpg");
				Bundle extras = new Bundle();
				extras.putStringArrayList("images", list);
				launcherActivity(ArticleDetailsActivity.this, CheckImagesActivity.class, extras);
			}
		});

		attention.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (isAttention) {
					attention.setImageResource(R.drawable.attention_select);
					isAttention = false;
				} else {
					attention.setImageResource(R.drawable.attention_nomal);
					isAttention = true;
				}
			}
		});
		linePraise.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (isPraise) {
					ivPraise.setImageResource(R.drawable.praise_select);
					tvPraise.setText("人气\n1213");
					isPraise = false;
				} else {
					ivPraise.setImageResource(R.drawable.praise_nomal);
					tvPraise.setText("人气\n1212");
					isPraise = true;
				}
			}
		});
		lineMessage.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				tvMessage.setText("评论\n1213");
				listview.getRefreshableView().setSelection(2);
			}
		});
		lineCollection.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				ivCollection.setImageResource(R.drawable.collection_select);
			}
		});
		lineShare.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				ShowShareView shareView = new ShowShareView(ArticleDetailsActivity.this);
				shareView.showView(lineShare);
			}
		});
		lineReport.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				ToastUtil.showToast(getApplicationContext(), "举报");
				launcherActivity(ArticleDetailsActivity.this, ReportActivity.class, null);
			}
		});
		showEmojii.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (facechoose.getVisibility() == View.VISIBLE) {
					facechoose.setVisibility(View.GONE);
					KeyBoardUtils.openKeybord(edMessage, ArticleDetailsActivity.this);
				} else {
					facechoose.setVisibility(View.VISIBLE);
					KeyBoardUtils.closeKeybord(edMessage, ArticleDetailsActivity.this);
				}
			}
		});
		edMessage.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (facechoose.getVisibility() == View.VISIBLE) {
					facechoose.setVisibility(View.GONE);
					KeyBoardUtils.openKeybord(edMessage, ArticleDetailsActivity.this);
				}
			}
		});

		((ArticleDetailsAdapter) commAdapter).setArticleDetailsClik(new ArticleDetailsClik() {
			@Override
			public void comments(String name) {
				edMessage.setText("");
				edMessage.setHint("回复" + name);
			}

			@Override
			public void chckUser(Object object) {

			}
		});
		btnSend.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				ToastUtil.showToast(getApplicationContext(), "发送 ");
			}
		});
	}

	@Override
	public void doInbackgroundCallBack() {
		List<Object> list = new ArrayList<Object>();
		for (int i = 0; i < 30; i++) {
			list.add(new Object());
		}
		baseAction.update(list);
	}

	@Override
	public void onPreExecuteCallBack() {

	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Object> doHandelData(Object object) {
		List<Object> list = (List<Object>) object;
		LoadingImages.getInstance().loadingImages("http://pic.baomihua.com/photos/201110/m_6_634546490868593750_15193389.jpg", userImg, getResources().getDimensionPixelSize(R.dimen.size_40));
		if (type == 0) {
			webView.setVisibility(View.VISIBLE);
			myWebView.loadUrl("http://wwww.baidu.com");
			loadImage.setVisibility(View.GONE);
		} else {
			webView.setVisibility(View.GONE);
			loadImage.setVisibility(View.VISIBLE);
			LoadingImages.getInstance().loadingImages("http://pic.baomihua.com/photos/201110/m_6_634546490868593750_15193389.jpg", img, 0);
		}
		userName.setText("等待11111");
		title.setText("我是测试标题");
		label.setText("隔壁家老王   测试");
		content.setText("详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容");
		return list;
	}

	@Override
	public void onItemClickCallBack(AdapterView<?> parent, View view, int position, long id) {

	}

	@Override
	public View getHeadView() {
		View view = LayoutInflater.from(ArticleDetailsActivity.this).inflate(R.layout.common_top_webview, null);
		line_bg = (LinearLayout) view.findViewById(R.id.line_bg);
		userImg = (ImageView) view.findViewById(R.id.userImg);
		userName = (TextView) view.findViewById(R.id.userName);
		attention = (ImageView) view.findViewById(R.id.attention);
		title = (TextView) view.findViewById(R.id.title);
		label = (TextView) view.findViewById(R.id.label);
		linePraise = (LinearLayout) view.findViewById(R.id.linePraise);
		ivPraise = (ImageView) view.findViewById(R.id.ivPraise);
		tvPraise = (TextView) view.findViewById(R.id.tvPraise);
		lineMessage = (LinearLayout) view.findViewById(R.id.lineMessage);
		tvMessage = (TextView) view.findViewById(R.id.tvMessage);
		lineCollection = (LinearLayout) view.findViewById(R.id.lineCollection);
		ivCollection = (ImageView) view.findViewById(R.id.ivCollection);
		lineShare = (LinearLayout) view.findViewById(R.id.lineShare);
		lineReport = (LinearLayout) view.findViewById(R.id.lineReport);
		webView = (WebView) view.findViewById(R.id.webView);
		myWebView = new MyWebView(ArticleDetailsActivity.this, webView);
		loadImage = (RelativeLayout) view.findViewById(R.id.loadImage);
		img = (ImageView) view.findViewById(R.id.img);
		imgNumber = (TextView) view.findViewById(R.id.imgNumber);
		content = (TextView) view.findViewById(R.id.content);
		return view;
	}

	@Override
	public View getFooterView() {
		FaceConversionUtil.getInstace().getFileText(getApplication());
		View view = LayoutInflater.from(ArticleDetailsActivity.this).inflate(R.layout.common_emoji_view, null);
		facechoose = (RelativeLayout) view.findViewById(R.id.ll_facechoose);
		layout = (FaceRelativeLayout) view.findViewById(R.id.FaceRelativeLayout);
		edMessage = (EditText) view.findViewById(R.id.edMessage);
		showEmojii = (ImageView) view.findViewById(R.id.showEmojii);
		btnSend = (ImageView) view.findViewById(R.id.btnSend);
		layout.setEditText(edMessage);
		return view;
	}

	@Override
	public Mode getListViewMode() {
		return BOTH;
	}
}
